#!/bin/sh

#
# Test that the `--exit-handshake` flag emits a CTRL+Z and then the exit code
#

. "$(cd "$(dirname "$0")" && pwd)/common.sh"

cat >$CONFIG <<EOF
task complete {
}
EOF

$FWUP_CREATE -c -f $CONFIG -o $FWFILE

# Run the command and turn the `\r`s into newlines to make
# it easy to compare with the expected output. The
# call to sed is to discard the final `\r` that's present
# on Windows.
cat /dev/null | $FWUP_APPLY --exit-handshake -a -d $IMGFILE -i $FWFILE -t complete \
    | tr '\032' '@' \
    | tr '\0' '!' \
    | tr '\r' '\n' \
    | sed '/^$/d' \
    | grep -v '^Elapsed time' \
    > $WORK/actual_output.txt

cat >$WORK/expected_output.txt <<EOF
  0% [                                    ]
100% [====================================]
Success!
@!
EOF
diff $WORK/expected_output.txt $WORK/actual_output.txt

# Check that the verify logic works on this file
$FWUP_VERIFY -V -i $FWFILE

